import { HttpClient } from '@angular/common/http'
import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store'
import { ActivatedRoute, Router} from '@angular/router'
import { Observable } from 'rxjs'
interface AppState {
    message: string;
}
export interface equipmentElement {
  id: number;
  model: string;
  manufactureDate: Date;
}

@Component({
  selector: 'app-equipment-list',
  templateUrl: './equipment-list.component.html',
  styleUrls: ['./equipment-list.component.sass']
})
export class EquipmentListComponent implements OnInit {
  message$: Observable<string>
  posts: any;
 ELEMENT_DATA: equipmentElement[] = [
];
  constructor(private router:Router,private store: Store<AppState>,private http:HttpClient,
    private route: ActivatedRoute) {
      this.message$ = this.store.select('message')
    }


  id:any;
  ngOnInit(): void {
  }
  getList() {
      this.posts = this.http.get('http://localhost:8000/equipments')
    }

  rmitem(item:string){
      if(confirm('do really want to delete this item?')){

       let res = this.http.delete(`http://localhost:8000/equipments/${item}`)
       res.subscribe(
           data => alert('deletion success'),
        error => alert('oops')
        )
        }else {
          alert("you hit cancel")
        }
    }
  spanishMessage(){
       this.store.dispatch({type: 'SPANISH'})
    }
  englishMessage() {
      this.store.dispatch({type: 'ENGLISH'})
    }
    gotoPage(pageName:string):void{
        this.router.navigate([`${pageName}`]);
    }
  displayedColumns: string[] = ['id', 'model', 'manufactureDate','operation'];
  dataSource = [] 
}
